package com.terry.gametest.test.service.impl;

//import com.terry.gametest.test.annotation.LogAndCache;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.terry.common.utils.PageUtils;
import com.terry.common.utils.Query;
import com.terry.gametest.test.annotation.LogAndCache;
import com.terry.gametest.test.dao.UserDao;
import com.terry.gametest.test.entity.UserEntity;
import com.terry.gametest.test.service.UserService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {

    @Value("${test.tan:}")
    public String testValue ;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<UserEntity> page = this.page(
                new Query<UserEntity>().getPage(params),
                new QueryWrapper<UserEntity>()
        );

        return new PageUtils(page);
    }

    @Cacheable(value = "USER_TB",key = "#name")
    @LogAndCache(key = "#name",cacheName = "USER_TB",needLog = true)
    public UserEntity getUser(String name){
        UserEntity userEntity = new UserEntity();
        userEntity.setName(name);
        UserEntity userEntity2 = this.getOne(new QueryWrapper<UserEntity>(userEntity));
        System.out.println("hhhhh");
        return userEntity2;
    }

    @CacheEvict(value = "USER_TB",key = "#userEntity.name")
    public void insertUser(UserEntity userEntity){
        this.saveOrUpdate(userEntity);
    }

}